import {CHANGE_LIST} from "./constants";

const changeList = (list) => ({
  type: CHANGE_LIST,
  list
});

export const getHomeList = () => {
  return (dispatch, getState, axiosInstance/**←需要开启store/index.js下的thunk.withExtraArgument*/) => {
    return axiosInstance.get('/api/news').then((res)=>{
      const list = res.data.data;
      dispatch(changeList(list));
    });

    // return new Promise((resolve, reject) => { // 这样返回的话 store.dispatch(actions.getHomeList()) 的返回值也将是一个promise,即这里设置的promise
    //   setTimeout(()=>{
    //     console.log('getHomeList 请求回结果');
    //     dispatch(changeList([1, 2, 3, 4, 5]));
    //     resolve();
    //   },300)
    // });
  };
};
